<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * Auth page
 *
 * GET /MobiMESH-CP/auth/?stage=counters&ip=192.168.168.254&mac=00:06:4F:7B:2E:F6&token=a10548a1308743618ccfbfe01eb436ee&incoming=0&outgoing=0&gw_id=local-gateway HTTP/1.0
 * GET /MobiMESH-CP/auth/?stage=logout&ip=192.168.168.254&mac=00:06:4F:7B:2E:F6&token=00%3A06%3A4F%3A7B%3A2E%3AF61301438014&incoming=0&outgoing=0&gw_id=local-gateway HTTP/1.0
 *
 */

require('../status.php');

//$valid_token = "a10548a1308743618ccfbfe01eb436ee";
$valid_token = $status['token'];

$stage = null;
$token = null;

if (isset($_REQUEST["token"])) {
   $token = $_REQUEST['token'];
}

if (isset($_REQUEST["stage"])) {
   $stage = $_REQUEST['stage'];
}

if ( $stage != null && $stage == "logout" )
{
    $fp = fopen('../status.php' , 'w');
    fputs($fp, "<?\r\n");
    fputs($fp, "\t\$status['token'] = \"\";\r\n");
    fputs($fp, "\t\$status['url'] = \"\";\r\n");
    fputs($fp, "\r\n?>\r\n");
    fclose($fp);
}
else
{
    if ( $token != null && $token == $valid_token )
    {
        print "Auth: 1";
    }
    else
    {
        print "Auth: 0";
    }
}
?>
